package Lee_code;

/**
 * @author blh
 * @date 2024年08月07日 18:39
 */
public class Lee_525_87 {
    int res = 0;

    public int findMaxLength(int[] nums) {
        int len = nums.length;
        if (len < 2) {
            return 0;
        }
        for (int i = 0; i < len - 1; i++) {
            judge(i, i + 1, nums);
        }
        return res;
    }

    private void judge(int left, int right, int[] nums) {
        int oneNum = 0, zeroNum = 0;

        while (left >= 0 && right <= nums.length - 1) {
            if (nums[left] == 1) {
                oneNum++;
            } else {
                zeroNum++;
            }
            if (nums[right] == 1) {
                oneNum++;
            } else {
                zeroNum++;
            }
            if (zeroNum == oneNum) {
                res = Math.max(res, zeroNum + oneNum);
            }
            right++;
            left--;
        }
    }
}
